﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MShop.Core.DataAccess;
using MShop.Core.Domain;

namespace MShop.Web.Controllers
{

    public class HelpController : ControllerBase
    {
        private readonly ICommonDao<HelpItem> _CommonDao;
        private readonly IProductDao _ProductDao;
        private readonly IArticleDao _ArticleDao;
        private readonly ICommonDao<HelpCategory> _CommonDao2;
        public HelpController(ICommonDao<HelpItem> commonDao, IProductDao productDao, IArticleDao articleDao, ICommonDao<HelpCategory> commonDao2)
        {
            _CommonDao = commonDao;
            _ProductDao = productDao;
            _ArticleDao = articleDao;
            _CommonDao2 = commonDao2;
        }

        [OutputCache(Duration = 600, Location = System.Web.UI.OutputCacheLocation.Any, NoStore = false, VaryByParam = "Id")]
        public ActionResult Item(int id)
        {
            var Model = _CommonDao.GetById(id);
            string description = string.IsNullOrEmpty(Model.Summary) ? Model.SlashEncodeContent(120) : Model.Summary;
            AppendMeta(string.Concat(Model.Title, "-", Model.HelpCategory.Name), Model.Title, description);
            return View(Model);
        }

        public ActionResult Index()
        {
            AppendMeta("帮助中心");
            HelpItem item =  _CommonDao.FirstOrDefault();
            return RedirectToAction("item", new { id = item.Id });
        }

        [OutputCache(Duration=600,Location=System.Web.UI.OutputCacheLocation.Any,NoStore=false,VaryByParam="*")]
        public ActionResult Menu()
        {
            return PartialView("help/menu", _CommonDao2.GetAll().OrderBy(x=>x.Sort).ToList());
        }

    }
}
